package com.ericzong.renamer.converter.string;

import org.apache.commons.lang3.StringUtils;

import com.ericzong.renamer.model.Record;

public class AddStringConverter extends AbstractStringConverter
{
	private String startString;
	private String endString;
	private String insertString;
	private int insertIndex;
	
	public AddStringConverter()
	{
		startString = StringUtils.EMPTY;
		endString = StringUtils.EMPTY;
		insertString = StringUtils.EMPTY;
		insertIndex = 1;
	}

	@Override
	public void convert(Record record)
	{
		StringBuffer target = new StringBuffer(record.getSource());
		
		if(StringUtils.isNoneEmpty(insertString))
		{
			target.insert(getIndex(insertIndex, target.length()), insertString);
		}
		
		if(StringUtils.isNoneEmpty(startString))
		{
			target.insert(0, startString);
		}
		
		if(StringUtils.isNoneEmpty(endString))
		{
			target.append(endString);
		}
		
		record.setTarget(target.toString());
	}

	public String getStartString()
	{
		return startString;
	}

	public void setStartString(String startString)
	{
		this.startString = startString;
	}

	public String getEndString()
	{
		return endString;
	}

	public void setEndString(String endString)
	{
		this.endString = endString;
	}

	public String getInsertString()
	{
		return insertString;
	}

	public void setInsertString(String insertString)
	{
		this.insertString = insertString;
	}

	public int getInsertIndex()
	{
		return insertIndex;
	}

	public void setInsertIndex(int insertIndex)
	{
		this.insertIndex = insertIndex;
	}
	
}
